//
//  LMWelcome.swift
//  WeiBo
//
//  Created by Li MAc on 2018/11/27.
//  Copyright © 2018 Li MAc. All rights reserved.
//

import UIKit
import SDWebImage
class LMWelcome: UIView {

    @IBOutlet weak var img: UIImageView!
    
    @IBOutlet weak var comLabel: UILabel!
    
    @IBOutlet weak var bottomHight: NSLayoutConstraint!
    
    class func comView() -> LMWelcome {
        let nib = UINib(nibName: "WelcomeView", bundle:nil)
        
        let v = nib.instantiate(withOwner: nil, options: nil)[0]
        
        return v as! LMWelcome
    }
    
    //自动布局跟新完约束会调用此方法
//    override func layoutSubviews() {
//        <#code#>
//    }
    // 视图已经添加到window上，表示视图已经显示
    override func didMoveToWindow() {
    
        bottomHight.constant = bounds.size.height - 200
        
        //withDuration(动画时长) delay（延时时长）
        UIView.animate(withDuration: 1.0, delay: 0, options: [], animations: {
            //跟新约束
            self.layoutIfNeeded()
        }) { (_) in
            
            UIView.animate(withDuration: 1.0, animations: {
                self.comLabel.alpha = 1
            }, completion: { (_) in
                self.removeFromSuperview()
            })
            
        }
        
    }
    
    
    //设置t头像
    override func awakeFromNib() {
        guard let imgurl = LMNetworkTools.shared.userSG.avatar_large,let url = URL(string: imgurl) else{
            return
        }
        img.sd_setImage(with: url, placeholderImage: UIImage(named: "avatar_default"))
        
        img.layer.cornerRadius = 42.5
        img.layer.masksToBounds = true
    }
}
